#pragma once
#ifndef LIT__SCRIPT_CONTEXT_HH__
#define LIT__SCRIPT_CONTEXT_HH__

#include "LitScriptPrereqs.h"

namespace Lit
{
	class ScriptEngine;

	class ScriptContext
	{
	public:
		typedef asIScriptContext	Type;
		typedef RefPtr<Type>		Ptr;

	protected:
		Ptr mContext;
		RefPtr<ScriptEngine>	mEngine;
		bool					mCreated;
		ScriptContextState		mState;
	public:
		ScriptContext( const Ptr &context = Ptr(), RefPtr<ScriptEngine> engine = RefPtr<ScriptEngine>() );
		ScriptContext( const ScriptContext& rhs );
		virtual ~ScriptContext();
		
		static std::string trExecutionState( ScriptContextState state )
		{
			switch( state )
			{
				case SCS_EXECUTION_FINISHED: return "Finished";
				case SCS_EXECUTION_SUSPENDED: return "Suspended";
				case SCS_EXECUTION_ABORTED: return "Aborted";
				case SCS_EXECUTION_EXCEPTION : return "Exception";
				case SCS_EXECUTION_PREPARED : return "Prepared";
				case SCS_EXECUTION_ACTIVE : return "Active";
				case SCS_EXECUTION_ERROR: return "Error";
				case SCS_EXECUTION_UNINITIALIZED:
				default: 
					return "Uninitialized";
			}
		}
		ScriptContextState getState() const;
		size_t getLastExceptionLine() const;
		std::string getLastException() const;
		std::string getLastExceptionFunction() const;

		ScriptContextState execute( );
		
		bool isCreated() const{ return mCreated; }
		
		void create();
		void release();

		int prepare(ScriptFunctionPtr& func);
		
		const RefPtr<ScriptEngine>& getEngine() const;
		RefPtr<ScriptEngine>& getEngine();

		const Ptr& data() const;
		Ptr& data();
	};

};

#endif